
/**
 * 杂项工具类;
 * 可以将不好分类的工具函数放在该类目下;
 */

import { glConfig } from "../Config/GLConfig";
import FPJDefine from "../Game/FPJ/Prefabs/FPJDefine";
class Utils {
	header_altas = null;
	gameIcon_altas = null;
	_timeouts = null;
	_NEC_OnlyOnce = null;
	_NEC_once = null;
	accountList = [];
	curAccount = {};
	init() {
		// this.registerErrorHandler();
		this.header_altas = null;
		this.gameIcon_altas = null;
		this.getAccountList();
		console.log("-----GLUtils is init!");
	}
	onDestroy() {
		cc.vv.GLUtils.clearTimeout();
	}
	/**
	 * 创建文件夹;
	 */
	makeDir(path) {
		var folders = path.split("/");
		if (folders == null) {
			return false;
		}
		var dir = "";
		for (var i = 0; i < folders.length - 1; i++) {
			dir = dir + folders[i] + "/";
			jsb.fileUtils.createDirectory(dir);
		}
		return true;
	}
	/**
	 * byteArray to js obj;
	 */
	convertArrayToJSObj(data) {
		if (!data) {
			return;
		}
		var byteArray = new Uint8Array(data);
		var liststr = "";
		for (let index = 0; index < byteArray.length; index++) {
			const element = byteArray[index];
			var charValue = String.fromCharCode(element);
			//console.log("charValue:"+charValue);
			liststr += charValue;
		}
		var obj = JSON.parse(liststr);
		console.log("liststr:" + obj);
		return obj;
	}
	/**
	 * 将字符串转换成二进制形式，中间用空格隔开
	 * @param {*} str
	 */
	strToBinary(str) {
		var result = [];
		var list = str.split("");
		for (var i = 0; i < list.length; i++) {
			if (i != 0) {
				result.push(" ");
			}
			var item = list[i];
			var binaryStr = item.charCodeAt().toString(2);
			result.push(binaryStr);
		}
		return result.join("");
	}
	/**
	 * 退出游戏;
	 * tocomplete:
	 */
	exitGame() {
		cc.game.end();
	}
	/**
	 * 切换账号;
	 */
	changeAccount() {
		this.clearUserInfo();
		this.repetLogin(true);
	}
	clearUserInfo() {
		this.clearAccountInfo();
	}


	//重新登录
	repetLogin(isAutoLogin) {
		if (cc.vv.NetGameHall) {
			cc.vv.NetGameHall.close(true);
			cc.vv.NetGameHall = null;
		}
		cc.vv.uuid.clear();
		cc.vv.audioUtil.stopAll();
		cc.vv.sceneMgr.openScene("login", isAutoLogin);
		//  cc.vv.GLSceneMgr.loadScene("Login");
	}

	/**
	 * 重启游戏;
	 */
	restart() {
		cc.vv.audioUtil.stopAll();
		cc.sys.garbageCollect();
		// cc.vv.GLPageMgr.onDestroy();

		cc.game.restart();
	}

	/**
	 * 获取本地时间;
	 */
	getLocalTime(format) {
		var d = new Date();
		if (typeof format === "undefined") {
			return d.getTime();
		}
		return this.dateFormat(format, d);
	}
	dateFormat(fmt, date) {
		var o = {
			"M+": date.getMonth() + 1, //月份
			"d+": date.getDate(), //日
			"h+": date.getHours(), //小时
			"m+": date.getMinutes(), //分
			"s+": date.getSeconds(), //秒
			"q+": Math.floor((date.getMonth() + 3) / 3), //季度
			S: date.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(
				RegExp.$1,
				(date.getFullYear() + "").substr(4 - RegExp.$1.length)
			);
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(
					RegExp.$1,
					RegExp.$1.length == 1
						? o[k]
						: ("00" + o[k]).substr(("" + o[k]).length)
				);
		return fmt;
	}
	/**
	 * 日期格式化
	 * @param {毫秒} mstime
	 */
	formatDate(mstime) {
		var date = new Date(mstime);
		var year = date.getFullYear();
		var mon = date.getMonth() + 1;
		var _mon = mon + "";
		if (mon < 10) {
			_mon = "0" + mon;
		}
		var day = date.getDate();
		var hour = date.getHours();
		var _hour = hour + "";
		if (hour < 10) {
			_hour = "0" + hour;
		}
		var min = date.getMinutes();
		var _min = min + "";
		if (min < 10) {
			_min = "0" + min;
		}
		var final = "" + year + "-" + _mon + "-" + day + " " + _hour + ":" + _min;
		return final;
	}
	/**
	 * 获取服务器时间;
	 */
	getServerTime() {
		var mill = cc.vv.GLNetDataModel.getDiffServerTime() + new Date().getTime();
		return mill;
	}
	/**
	 * 显示黑条提示;
	 * @param {提示信息}} msg
	 */
	showTips(msg) {
		console.log("____tips_____", msg);
		cc.vv.UIMgr.open(cc.vv.GLConfig.tips_path, null, null, msg);
	}

	/**
	 * 显示警告弹窗;
	 * @param {*} content
	 * @param {*} functionOK
	 * @param {*} needcancel
	 * @param {*} functionCancel
	 */
	showAlert(content, functionOK = function () { }, functionCancel, parent, titleSpt = 0) {
		//cc.vv.GLUtils.showAlert1(content, function () { functionOK() }.bind(this), function () { functionCancel() }.bind(this), parent);
		cc.vv.UIMgr.open(cc.vv.GLConfig.alert_path, parent, null, content, functionOK, functionCancel, titleSpt);
		cc.log("showAlert ::=====>", content);
	}

	/**
	 * 显示警告弹窗;
	 * @param {*} content
	 * @param {*} functionOK
	 * @param {*} needcancel
	 * @param {*} functionCancel
	 */
	showAlert1(content, functionOK = function () { }, functionCancel = null, parent = null, titleSpt = "", okText = "", cancleText = "", nodey = null, isRichText: boolean = false) {//, okLabel = '确定', cancelLabel = '取消'
		cc.vv.UIMgr.open(cc.vv.GLConfig.alert1_path, parent, null, content, functionOK, functionCancel, titleSpt, okText, cancleText, nodey, isRichText);//, okLabel, cancelLabel
		cc.log("showAlert1 ::=====>", content);
	}

	/**
	 * 多级警告弹窗;
	 * @param {}} content
	 * @param {*} functionOK
	 * @param {*} needcancel
	 * @param {*} functionCancel
	 */
	showMutilAlert(content, functionOK, needcancel, functionCancel) {
		// var nodeFind = cc.vv.persistNode;
		var tipNode = cc.director.getScene().getChildByName("Canvas");
		if (!tipNode) {
			return;
		}
		var widgetName = "Alert";
		var url = "Components/CommonWidget/" + widgetName + "/Prefab/" + widgetName;
		var nodePre = cc.find(widgetName, tipNode);
		if (nodePre) {
			var node = cc.instantiate(nodePre);
			node.zIndex = cc.vv.GLDefine.EHierarchy.HIGHEST + tipNode.childrenCount;
			tipNode.addChild(node);
			node.setPosition(0, 0);
			node
				.getComponent(widgetName)
				.show(content, functionOK, needcancel, functionCancel);
		} else {
			cc.loader.loadRes(url, (err, prefab) => {
				if (!err) {
					var node = cc.instantiate(prefab);
					//  node.zIndex = cc.vv.GLDefine.EHierarchy.HIGHEST + tipNode.childrenCount;
					tipNode.addChild(node);
					node.setPosition(0, 0);
					node
						.getComponent(widgetName)
						.show(content, functionOK, needcancel, functionCancel);
				} else {
					console.log("-------showMutilAlert load res failed url: " + url);
				}
			});
		}
	}

	/**
	 * 长度缩略;
	 */
	convertShortNum(
		string,
		isChinese,
		isFour //isFour开启4位缩减
	) {
		if (!string) {
			return string;
		}
		if (!cc.vv.core.isNumber(string)) {
			return string;
		}
		var num = string;
		var w = "W";
		var y = "Y";
		if (isChinese != undefined && isChinese == true) {
			//w = cc.vv.GLocalizationDataModel.getStringByKey("Chinese_W")
			//y = cc.vv.GLocalizationDataModel.getStringByKey("Chinese_Y")
		}

		if (isFour) {
			if (num <= 9999) {
				num = "" + num;
				return num;
			} else if (num <= 99999) {
				num = (num / 10000).toFixed(1) + w;
				return num;
			}
		} else {
			if (num <= 99999) {
				num = "" + num;
				return num;
			}
		}

		if (num <= 999999) {
			num = Math.floor(num / 100) / 100 + w;
		} else if (num <= 9999999) {
			num = Math.floor(num / 1000) / 10 + w;
		} else if (num <= 99999999) {
			num = Math.floor(num / 10000) + w;
		} else if (num <= 999999999) {
			num = Math.floor(num / 100000) / 1000 + y;
		} else if (num <= 9999999999) {
			num = Math.floor(num / 1000000) / 100 + y;
		} else if (num <= 99999999999) {
			num = Math.floor(num / 10000000) / 10 + y;
		} else {
			num = Math.floor(num / 100000000) + y;
		}
		return num;
	}
	getShortStr(str, num) {
		var _arr = Array.from(str);
		var _str = "";
		if (_arr.length > num) {
			_str = "...";
		}
		return _arr.slice(0, num).join('') + _str;
	}
	/**
	 * 长字符串切为短字符串多余部分用...代替;
	 * @param {*} str
	 * @param {*} num 除去...剩余的位数
	 * @example
	 * str = "一二三四"
	 * cc.vv.GLUtils.getShortStr(str,4) => "一二三四"
	 * str = "一二三四五六"
	 * cc.vv.GLUtils.getShortStr(str,4) => "一二三..."
	 *
	 */
	getShortStr1(str, num) {
		if (!str) {
			return "";
		}
		if (!num) {
			num = 4;
		}

		//  补偿"..."占的一位
		num++;

		var reg = /^[\u4e00-\u9fa5]+$/;

		let tag = 0;
		let res = "";
		let haveMoreTag = false;
		let lastRes = "";
		for (let c of str) {
			//还有剩余数据 那么追加"..."
			if (haveMoreTag) {
				res = lastRes + "...";
				break;
			}

			let isChinese = reg.test(c);
			let isEmoji = this.checkEmoji(c);

			//汉字 占1位宽度
			if (isChinese || isEmoji) {
				tag += 1;
			}
			//英文 占0.5位宽度
			else {
				tag += 0.5;
			}
			//如果满足条件了
			lastRes = res;
			res = res + c;
			if (tag >= num) {
				haveMoreTag = true;
			}

			//   cc.log("getShortStr c =  ",c,"汉字 ->",isChinese,"表情 ->",isEmoji,"结果 ->",res)
		}

		return res;
	}

	//检查是否为emoji表情
	checkEmoji(str) {
		// 正则来源来自 https://www.npmjs.com/package/emoji-regex
		var reg = /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD]|[\u2660-\u2767]\u0020)/g;
		var r = reg.test(str);
		return r;
	}



	//保存电话号码/密码;
	saveAccountInfo(accountInfo) {
		// let data = {
		// 	phone_num: accountInfo.phone_num || "",
		// 	uuid: accountInfo.uuid || "",
		// 	vcode : accountInfo.vcode,
		//  logintoken : accountInfo.logintoken, //
		// };
		var id = cc.vv.session.getId();
		cc.vv.GLCusStorage.setItem("accountInfo" + id, JSON.stringify(accountInfo));
	}
	//获取电话号码和密码;
	getAccountInfo() {
		var id = cc.vv.session.getId();
		var info = cc.vv.GLCusStorage.getItem("accountInfo" + id);
		if (info) {
			info = JSON.parse(info);

			return info;
		}
		return {};
	}
	clearAccountInfo() {
		if(FPJDefine){
			FPJDefine.resetAllData()
		}
		if(cc.vv.session){
			cc.vv.session.reset()
		}
		var id = cc.vv.session.getId();
		cc.vv.GLCusStorage.removeItem("accountInfo" + id);
	}

	/*
	{
	  rid : 000,
	  cpass : 0,
	  user_name : "",
	  auth_type : 1,
	  phone_num : 138345353
	  UUID:"wewrwtet"
	}
	*/
	//curAccount
	getCurAccount() {
		let _account = cc.vv.GLCusStorage.getItem("curAccount");
		if (!_account || _account == "undefined") {
			this.curAccount = null;
		} else {
			this.curAccount = JSON.parse(_account);//_accountList.split(",");//JSON.parse(_gameList);
		}
		return this.curAccount;
	}
	setCurAccount(data) {
		this.curAccount = data;
		cc.vv.GLCusStorage.setItem("curAccount", JSON.stringify(this.curAccount));
	}

	clearCurAccount() {
		cc.vv.GLCusStorage.removeItem("curAccount");
	}

	getAccountList() {
		let _accountList = cc.vv.GLCusStorage.getItem("accountList");
		if (!_accountList) {
			this.accountList = [];
		} else {
			this.accountList = JSON.parse(_accountList);//_accountList.split(",");//JSON.parse(_gameList);
		}
		return this.accountList;
	}
	setAccountList(data) {
		this.accountList = data;
		cc.vv.GLCusStorage.setItem("accountList", JSON.stringify(this.accountList));
	}
	addAccountList(data) {
		for (var i = 0; i < this.accountList.length; i++) {
			if (data.rid == this.accountList[i].rid) {
				break;
			}
		}
		this.accountList.splice(i, 1);
		this.accountList.splice(0, 0, data);
		this.setAccountList(this.accountList);
	}

	clearAccountList() {
		cc.vv.GLCusStorage.removeItem("accountList");
	}


	saveUpdateFaild(isFaild) {
		cc.sys.localStorage.setItem("updataFaild", JSON.stringify(isFaild));
	}
	getUpdateFaild() {
		var _isFaild = cc.sys.localStorage.getItem("updataFaild");
		_isFaild = JSON.parse(_isFaild);
		if (!_isFaild) {
			_isFaild = "";
		}
		return _isFaild;
	}
	//清除缓存;
	cleanCache() {
		var storage_path = jsb.fileUtils ? jsb.fileUtils.getWritablePath() : "/";
		jsb.fileUtils.removeDirectory(storage_path + "temp");
		jsb.fileUtils.removeDirectory(storage_path + "upddir");
		jsb.fileUtils.removeFile(storage_path + "update/" + "version.manifest");
		jsb.fileUtils.removeFile(storage_path + "update/" + "project.manifest");
		cc.game.restart();
	}

	//转换成千分位数字
	getCommaNumber(number) {
		if (typeof number === "number") {
			return number.toString().replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
		} else {
			return "0";
		}
	}
	/**
	 * 
	 * @param gameId 
	 * @param callBack 
	 */
	getGameIcon(gameId, callBack) {
		var _gameInfo = cc.vv.GameChooseConfig.getgameInfoByGameId(gameId);
		if (!_gameInfo) {
			if (callBack) {
				callBack();
			}
			return;
		}
		if (!this.gameIcon_altas) {
			cc.loader.loadRes("Common/GameIcon/GameIcon", cc.SpriteAtlas, (error, resource) => {
				if (!error) {
					this.gameIcon_altas = resource;

					if (callBack) {
						callBack(this.gameIcon_altas.getSpriteFrame(_gameInfo.iconName), gameId);
					}
				} else {
					if (callBack) {
						callBack(null, gameId);
					}
				}
			});
		} else {
			if (callBack) {
				callBack(this.gameIcon_altas.getSpriteFrame(_gameInfo.iconName), gameId);
			}
		}
	}

	/**
	 * 获取帧图片
	 * @param {} logo  
	 * @param {*} callBack   请求成功后的回调函数
	 */
	// getSprite(logo: string, callBack) {
	// 	if (!this.header_altas) {
	// 		cc.loader.loadRes("Common/HeadImg/HeadImg", cc.SpriteAtlas, (error, resource) => {
	// 			if (!error) {
	// 				this.header_altas = resource;

	// 				if (callBack) {
	// 					callBack(this.header_altas.getSpriteFrame(logo + ""));
	// 				}
	// 			} else {
	// 				if (callBack) {
	// 					callBack();
	// 				}
	// 			}
	// 		});
	// 	} else {
	// 		if (callBack) {
	// 			callBack(this.header_altas.getSpriteFrame(logo + ""));
	// 		}
	// 	}
	// }

	getSprite(logo: string, callBack) {
		let headPath = `Common/HeadIcon/head_${logo}`
		cc.loader.loadRes(headPath, cc.SpriteFrame, (error, resource) => {
			if (resource == null)
				console.log("加载 本地图片失败 path:" + headPath)
			if (error) {
				if (callBack)
					callBack(null)
				return
			}
			if (callBack)
				callBack(resource);
		});
	}

	/**
	 * 获取头像框
	 * @param {} logo  
	 * @param {*} callBack   请求成功后的回调函数
	 */
	getFrameSprite(logo: string, callBack) {
		// if (logo) {
		// 	logo = "TXK_" + logo;
		// } else {
		// 	logo = "TXK_0";
		// }
		logo = "TXK_0";

		this.getSprite(logo, callBack);
	}

	/**
	 * 获取头像
	 * @param {} logo  
	 * @param {*} callBack   请求成功后的回调函数
	 */
	getPlayerHeadSprite(logo: string, callBack) {
		console.log("--------logo_url:" + logo);
		if (!logo || logo.indexOf("http") < 0) {
			//	this.getSprite(logo || "0", callBack);
			this.getSprite(logo, callBack);
		} else {
			// this.getHeadImageByServer(logo, callBack)
			var arr = logo.split(".");
			if (arr.length > 0 && arr[arr.length - 1] && (arr[arr.length - 1] == "jpg" || arr[arr.length - 1] == "jpeg")) {
				//this.getQiNiuAvatar(logo, callBack);
				
			} else {
				this.getWechatAvatar(logo, callBack);
			}
		}
	}

	private getHeadImageByServer(logo: string, callBack): void {
		if (!cc.sys.isNative) {
			this.getSprite("0", callBack);
			return
		}
		let tempArr: string[] = logo.split("/")
		if (tempArr.length < 0) {
			this.getSprite("0", callBack);
			return
		}
		let dirpath = jsb.fileUtils.getWritablePath() + 'headimg/';
		let saveName: string = tempArr[tempArr.length - 1]
		this.loadImageNativeWithUrl(logo, (sp, flag) => {
			if (flag) {
				callBack(sp)
			} else {
				this.getSprite("0", callBack);
			}
		}, saveName, dirpath, "jpg")
	}

	//获取qiniu头像;
	//Mark:
	getQiNiuAvatar(logo_url, callBack) {
		console.log("---getQiNiuAvatar-----logo_url:" + logo_url);
		cc.loader.load(logo_url, (error, result) => {
			if (error) {
				console.log("-------getPlayerHeadSprite error:", error);
				this.getSprite("0", callBack);
				return;
			}
			console.log("-------getPlayerHeadSprite:");
			var spriteFrame = new cc.SpriteFrame();
			spriteFrame.setTexture(result);
			if (callBack) {
				callBack(spriteFrame);
			}
		});
	}
	//获取微信头像;
	getWechatAvatar(logo_url, callBack) {
		cc.loader.load({
			url: logo_url + "",
			type: "png"
		}, (error, result) => {
			if (error) {
				console.log("getWechatAvatar error:", error);
				//this.getDefaultAvatar(callBack);
				this.getSprite("0", callBack);
				return
			}
			var spriteFrame = new cc.SpriteFrame();
			spriteFrame.setTexture(result);
			if (callBack) {
				callBack(spriteFrame);
			}
		})
	}
	getDefaultAvatar(cb) {
		let url = cc.vv.GLDefine.DefaultHeadUrl;
		cc.loader.loadRes(url, (error, texture) => {
			if (!error) {
				var spriteFrame = new cc.SpriteFrame();
				spriteFrame.setTexture(texture);
				if (cb) {
					cb(spriteFrame);
				}
			} else {
				cc.error("默认头像读取失败,请检查->" + cc.vv.GLDefine.DefaultHeadUrl + ".png")
				if (cb) {
					cb();
				}
			}
		})

	}

	/**
	 * loadRes
	 * @param url Url of the target resource
	 * @param type Only asset of type will be loaded if this argument is supplied.
	 * @param callBack Callback invoked when the resource loaded.
	 */
	loadRes(url: string, type: typeof cc.Asset, callBack) {
		if (!url || url.indexOf("http") < 0) {//本地资源
			cc.loader.loadRes(url, type, (error, resource) => {
				if (error) {
					console.log("加载 本地图片失败 url:" + url);
					if (callBack) {
						callBack(null);
						return;
					}
				}
				if (callBack) {
					callBack(resource);
				}

			});
		} else {//网络资源
			cc.loader.load(url, (error, result) => {
				if (error) {
					console.log("加载 本地图片失败 url:" + url);

					if (callBack) {
						callBack(null);
						return;
					}
				}

				var spriteFrame = new cc.SpriteFrame();
				spriteFrame.setTexture(result);
				if (callBack) {
					callBack(spriteFrame);
				}
			});
		}

	}
	/**http日志输出
	 * con_str: 字符串提示;
	 */
	HttpLogOut(con_str) {
		try {
			var content = con_str;
			var rid = cc.vv.session.getRid();
			var userdata = cc.vv.GLUtils.getAccountInfo();
			var userdata_str = JSON.stringify(userdata) || "";
			let params = {
				rid: rid,
				content: content,
				userdata: userdata_str
			};
			let url = "http://baidu.com";
			cc.vv.GLHttpUtils.httpPost(url, params, function (data) {
				if (data === -1) {
					cc.error("HttpLogOut httpPost error !cry!");
				} else {
					console.log(
						"HttpLogOut success !! httpPost data: " + JSON.stringify(data || "")
					);
				}
			});
		} catch (error) {
			cc.error("HttpLogOut error !cry! :" + JSON.stringify(error.message));
		}
	}


	goldFlyAnimation(time, endPosition) {
		if (!time) {
			time = 0.4;
		}
		if (!endPosition) {
			return null;
		}
		var scaleToLarge = 1.5; //放大到 1.5
		var jumpHeight = 70; // 跳跃高度70
		var angleBorder = 180; // 正负 90

		var scale1 = cc.scaleTo(time / 2, scaleToLarge);
		var scale2 = cc.scaleTo(time / 2, 1);
		var seqScale = cc.sequence(scale1, scale2);

		var action = cc
			.jumpTo(time, endPosition.x, endPosition.y, jumpHeight, 1)
			.easing(cc.easeQuarticActionOut());

		var angle = Math.random() * angleBorder - angleBorder / 2;
		var action_2 = cc.rotateTo(time + 0.1, angle);
		var spawn = cc.spawn(action, action_2, seqScale);
		return spawn;
	}
	random(min, max) {
		switch (arguments.length) {
			case 1:
				return parseInt(Math.random() * min + 1 + "");
			case 2:
				return parseInt(Math.random() * (max - min + 1) + min);
			default:
				return Math.random();
		}
	}

	//禁止同时点击两个按钮
	prohibitDoubleBtnClick() {
		var touchBtn = [];
		var touchTime = Date.now();
		cc.Button.prototype["_onTouchBegan"] = function (event) {
			if (!this.interactable || !this.enabledInHierarchy || Date.now() - touchTime < 100) {
				return;
			}

			touchBtn.push(this);
			touchTime = Date.now();
			this._pressed = true;
			this._updateState();
			event.stopPropagation();
		};
		cc.Button.prototype["_onTouchEnded"] = function (event) {
			if (!this.interactable || !this.enabledInHierarchy) return;
			if (this._pressed) {
				cc.Component.EventHandler.emitEvents(this.clickEvents, event);
				this.node.emit("click", this);
				touchBtn.map(btn => (btn["_pressed"] = false));
				touchBtn.length = 0;
			}
			this._pressed = false;
			this._updateState();
			event.stopPropagation();
		};
	}
	//删除数组重复元素
	deleteArrayRepeatElements(arr) {
		var result = [],
			hash = {};
		for (var i = 0, elem; (elem = arr[i]) != null; i++) {
			if (!hash[elem]) {
				result.push(elem);
				hash[elem] = true;
			}
		}
		return result;
	}

	// 2阶贝塞尔曲线公式
	twobsr(t, a1, a2, a3) {
		return ((1 - t) * (1 - t) * a1 + 2 * t * (1 - t) * a2 + t * t * a3).toFixed(
			3
		);
	}
	onebsr(t, a1, a2) {
		return a1 + (a2 - a1) * t;
	}


	/**
	 * 
	 * @param func 需要执行函数
	 * @param time 延迟 ms
	 * @param key 此定时器的键 (必须在OnDestroy 时调用clearTimeout)
	 * @param arg 传入函数的参数列表
	 */
	setTimeoutByKey(func, time, key = "default", ...arg) {
		let timeout = setTimeout(
			arg => {
				//执行完毕后清除这个TimeOut
				if (this._timeouts && this._timeouts[key]) {
					if (this._timeouts[key][timeout]) {
						delete this._timeouts[key][timeout];
					}
				}
				if (func) {
					func(arg);
				}
				return;
			},
			time,
			arg
		);
		if (!this._timeouts) this._timeouts = {};
		if (!this._timeouts[key]) this._timeouts[key] = {};

		this._timeouts[key][timeout] = timeout;

	}
	/**
	 * 
	 * @param key 需要关闭的定时器的键
	 */
	clearTimeout(key = "default") {
		if (this._timeouts && this._timeouts[key]) {
			for (const k in this._timeouts[key]) {
				var item = this._timeouts[key][k];
				if (item) {
					clearTimeout(item);
					delete this._timeouts[key][k];
				}
			}
			delete this._timeouts[key];
		}
	}
	/**
	 *
	 * @param {*} type 1对战 2百人 3 房间列表 4麻将 5炸金花游戏中
	 * @param {*} dt 间隔
	 */
	notEnoughCoin(type = 1, isNeedStandUp = true, needCoin: number = 0, dt = 5000) {
		// cc.vv.GLUtils.showTips('您的金币不足，请充值');

		cc.log("cc.vv.GLDefine.HoldScene", cc.vv.GLDefine.HoldScene);

		// cc.vv.audioUtil.playSound("Hall/Sound/button_onclicked");
		switch (type) {
			case 1:
				//对战场  需要站起然后退出游戏,打开充值界面

				cc.vv.UIMgr.open(cc.vv.GLConfig.notEnoughCoin_path, null, null, {
					isNeedStandUp: isNeedStandUp,
					isInGame: true,
					needCoin: needCoin
				});
				//播放音效
				if (!this._NEC_OnlyOnce) {
					cc.vv.audioUtil.playSound("Hall/sound/coin_notEnough_1");
					this._NEC_OnlyOnce = true;
					cc.vv.GLUtils.setTimeoutByKey(() => {
						this._NEC_OnlyOnce = false;
					}, 15000);
				}
				break;
			case 2:
				//一段时间只打开一次
				if (!this._NEC_once) {
					this._NEC_once = true;
					cc.vv.GLUtils.showTips("您的金币不足，请充值");
					cc.vv.audioUtil.playSound("Hall/sound/coin_notEnough_2");
					cc.vv.GLUtils.setTimeoutByKey(() => {
						this._NEC_once = false;
					}, dt);
				}
				break;
			case 3:
				//一段时间只打开一次
				if (!this._NEC_once) {
					this._NEC_once = true;
					//lx:gai
					/* 	cc.vv.UIMgr.open(cc.vv.GLConfig.notEnoughCoin_path, null, null, {
							isNeedStandUp: true,
							isInGame: false,
							needCoin: needCoin
						}); */
					let str: string = `您的余额不足${needCoin}，是否前往充值`
					cc.vv.GLUtils.showAlert1(str,
						function () {
							//lx:
							cc.vv.GLUtils.changeCanvasToVertical()
							if (cc.vv.dataCfg.isHaveTransPass)
								cc.vv.UIMgr.open(cc.vv.GLConfig.chongZhi_path);
							else
								cc.vv.UIMgr.open(cc.vv.GLConfig.setTransPass_path, null, null);
							//TODO
						}.bind(this), function () { });
					cc.vv.audioUtil.playSound("Hall/sound/coin_notEnough_1");

					cc.vv.GLUtils.setTimeoutByKey(() => {
						this._NEC_once = false;
					}, dt);
				}
				break;
			case 4:
				//麻将匹配模式使用
				cc.vv.GLDefine.HoldScene = true;
				// cc.vv.GLPageMgr.openPage("Page_NotEnoughCoin", page => {
				//   if (page && page.node) {
				//     page.setNeedStandUp(false);
				//   }
				// });
				cc.vv.UIMgr.open(cc.vv.GLConfig.notEnoughCoin_path, null, null, {
					isNeedStandUp: false,
					isInGame: true,
					needCoin: needCoin
				});
				cc.vv.audioUtil.playSound("Hall/sound/coin_notEnough_1");
				break;
			default:
				cc.vv.GLUtils.showTips("您的金币不足，请充值");
				//一段时间只打开一次
				if (!this._NEC_once) {
					this._NEC_once = true;
					cc.vv.audioUtil.playSound("Hall/sound/coin_notEnough_2");
					cc.vv.GLUtils.setTimeoutByKey(() => {
						this._NEC_once = false;
					}, dt);
				}
				break;
		}
	}
	// registerErrorHandler() {
	// 	//未完成
	// 	if (cc.sys.isNative) {
	// 		window.__errorHandler = function (
	// 			errorMessage,
	// 			file,
	// 			line,
	// 			message,
	// 			error
	// 		) {
	// 			let exception = {};
	// 			exception.errorMessage = errorMessage;
	// 			exception.file = file;
	// 			exception.line = line;
	// 			exception.message = message;
	// 			exception.error = error;
	// 			if (window.exception != JSON.stringify(exception)) {
	// 				window.exception = JSON.stringify(exception);
	// 				console.log("exception  is  " + window.exception);
	// 				//TODO: 发送请求上报异常 //接口没有定义
	// 			}
	// 		};
	// 	} else if (cc.sys.isBrowser) {
	// 		window.onerror = function (errorMessage, file, line, message, error) {
	// 			let exception = {};
	// 			exception.errorMessage = errorMessage;
	// 			exception.file = file;
	// 			exception.line = line;
	// 			exception.message = message;
	// 			exception.error = error;
	// 			if (window.exception != JSON.stringify(exception)) {
	// 				window.exception = JSON.stringify(exception);
	// 				console.log("exception  is  " + window.exception);
	// 				//TODO: 发送请求上报异常//接口没有定义
	// 			}
	// 		};
	// 	}
	// }

	// //在大厅检测是否绑定了手机 同时打开绑定送金界面
	// checkPhoneBind(tips?) {
	// 	var baseInfo = cc.vv.session.getPlayer() || {};
	// 	if (baseInfo && !baseInfo.phone) {
	// 		// if (!tips) {
	// 		// 	tips = "您需要先绑定手机才能充值或者提款!";
	// 		// }
	// 		// cc.vv.GLUtils.showTips(tips);

	// 		return false;
	// 	}
	// 	return true;
	// }
	/**
	 * 
	 */
	backHallOpenRecharge(flag: boolean) {
		cc.vv.sceneMgr.openScene("hall", { isOpenChongZhi: flag }, () => {
			// let is_bind = this.checkPhoneBind();
			// if (!is_bind) {
			// 	cc.vv.UIMgr.open(cc.vv.GLConfig.Gift_path);
			// 	return;
			// }
			// if (flag) {
			// 	if (cc.vv.dataCfg.isHaveTransPass)
			// 		cc.vv.UIMgr.open(cc.vv.GLConfig.chongZhi_path);
			// 	else
			// 		cc.vv.UIMgr.open(cc.vv.GLConfig.setTransPass_path);
			// }
		});
	}
	//添加单位 元为单位
	_addUnit(str) {
		let MoneyType = "RMB";
		switch (MoneyType) {
			case "RMB":
				return str + "元";
			case "DOLLAR":
				return str + "";
			case "HKDOLLAR":
				return str + "";
			default:
				return str + "元";
		}
	}





	/** 取金币的缩减结果
	 * 
	 * @param num 
	 * @returns string
	 */

	getExchangeCoinNum(num) {
		switch (glConfig.platform) {
			case "WX":
			case "DW":
			case "DLM":
			case "FPJ":
				return this.getExchangeNumber(num);
			case "DWC":
				return this.getExchangeScore(num)
		}
	}


	//变换为字体可用字符串
	changeToFontString(str) {
		let change = cc.vv.GLDefine.FontKeyByCoin;
		let res = "";
		for (let c of str) {
			if (change[c]) {
				c = change[c];
			}
			res += c;
		}
		return res;
	}

	/**
	 * 简化为万亿数字 元为单位
	 * @example  cc.vv.GLUtils.getSimplified()
	 */
	getSimplified(number) {
		number = parseInt(number)
		let numberConfig = [
			"",//个
			"万",//: "万",
			"亿",//: "亿",
			"兆"
		]
		let symbol = ""
		if (number < 0) { // 处理负号
			symbol = "-"
			number = -number
		}
		let max = 3;
		for (let i = max; i > 0; i--) {
			let testN = Math.pow(10000, i)
			let t = number / testN
			if (!numberConfig[i]) break;
			if (t >= 1) {
				return symbol + Math.round(t * 100) / 100 + numberConfig[i]
			}
		}
		return symbol + Math.round(number * 100) / 100

	}


	/** 保留两位小数的换算方式
	 * 单位为分转换为单位为元
	 *  cc.vv.GLUtils.getExchangeNumber()
	 */
	getExchangeNumber(number) {
		let num = parseInt(number || 0);
		if (isNaN(num)) return "0";
		return (num / cc.vv.GLDefine.ZoomOutRatio).toFixed(2);
	}

	/** 舍弃小数的换算方式
	 *
	 * @param {*} number
	 * cc.vv.GLUtils.getExchangeScore()
	 */
	getExchangeScore(number) {
		let num = parseInt(number || 0);
		if (isNaN(num)) return "0";
		return Math.floor(num / cc.vv.GLDefine.ZoomOutRatio) + "";
	}









	/**
	 * 单位为分转换为单位为元  小数后保留两位但是不保留0
	 *  cc.vv.GLUtils.getExchangeNumber()
	 */
	getExchangeNumber2(number) {
		let num = Number(number || 0);
		if (isNaN(num)) return 0;
		num = Math.floor(num) / 100
		return num
	}


	/**
	 * 获取带单位的数字 分为单位
	 * @example  cc.vv.GLUtils.getUnitNumber()
	 */
	getUnitNumber(number) {
		return this._addUnit(this.getExchangeCoinNum(number));
	}
	/**
	 * 获取带单位的简化数字 分为单位
	 * @example  cc.vv.GLUtils.getUnitSimplifiedNumber()
	 */
	getNoUnitSimplified(number) {
		return this.changeToFontString(this.getSimplified(this.getExchangeCoinNum(number)));
	}

	getUnitSimplifiedNumber(number) {
		return this._addUnit(this.getSimplified(this.getExchangeCoinNum(number)));
	}
	getUnitScore(score) {
		return this._addUnit(this.getExchangeScore(score));
	}
	/**
	 * 获取字体可用的带单位数字 不保留小数 分为单位 主要用于.FNT
	 * @example  cc.vv.GLUtils.getFontUS()
	 */
	getFontUS(score) {
		return this.changeToFontString(this._addUnit(this.getExchangeCoinNum(score)));
	}
	/**
	 * 获取字体可用的带单位数字 分为单位 主要用于.FNT
	 * @example  cc.vv.GLUtils.getFontUN()
	 */
	getFontUN(str) {
		return this.changeToFontString(this.getUnitNumber(str));
	}
	/**
	 * 获取字体可用的带单位简化数字 分为单位
	 * @example  cc.vv.GLUtils.getFontUSN()
	 */
	getFontUSN(str) {
		return this.changeToFontString(this.getSimplified(this.getExchangeCoinNum(str)));
		//return this.changeToFontString(this.getUnitSimplifiedNumber(str));
	}

	findKey(obj, value, compare = (a, b) => a === b) {
		return Object.keys(obj).find(k => compare(obj[k], value));
	}

	checkNum(str) {
		var r = /^[0-9]*[1-9][0-9]*$/;
		if (r.test(str)) {
			return true;
		}
		return false;
	}


	/**
	 * 组装提示信息;
	 */
	printf() {
		var as = [].slice.call(arguments),
			fmt = as.shift(),
			i = 0;
		return fmt.replace(/%(\w)?(\d)?([dfsx])/ig, function (_, a, b, c) {
			var s = b ? new Array(b - 0 + 1).join(a || "") : "";
			if (c == "d") s += parseInt(as[i++]);
			if (c == "f") s += parseFloat(as[i++]);
			else if (c == "s") s += as[i++];
			return b ? s.slice(b * -1) : s;
		})
	}

	/**
	 * 服务器请求;
	 * @param {} cmd  请求命令
	 * @param {*} msg  请求时需要的参数
	 * @param {*} callBack   请求成功后的回调函数
	 */
	sendRequest(cmd: string, msg, callBack: (error, data) => void, isOpenWait?: Boolean) {
		if (cc.vv.NetGameHall) {
			if (isOpenWait) {
				cc.vv.UIMgr.open(cc.vv.GLConfig.waiting_path, null, null, "加载中...");
			}

			var _callBack = null;
			if (callBack) {
				_callBack = function (error, data) {
					cc.vv.UIMgr.close(cc.vv.GLConfig.waiting_path, cc.vv.UIMgr.closeType.hide);
					if (callBack) {
						callBack(error, data);
					}
				};
			}
			if (cmd == "EnterTable") {
				var club = cc.vv.session.getCurClub();
				if (club) {
					msg.club_id = club.Id || 0;
				} else {
					msg.club_id = 0;
				}
			}

			cc.vv.NetGameHall.sendRequest(cmd, msg || {}, _callBack);
		} else {
			//cc.vv.GLUtils.showTips("网络错误,请重启游戏再试！");
		}
	}

	getAdress(ip, callBack) {
		var address = "未知";
		if (!cc.sys.isNative) {
			if (callBack) {
				callBack(address);
			}
			return;
		}
		var url = cc.vv.GLConfig.getIPAdressUrl();
		/*
		// 淘宝接口
				url = url + "ip=" + ip;
				cc.vv.GLHttpUtils.httpGets(url, false, cc.vv.GLDefine.EXHRDataType.Text, (isOk, data) => {
					console.log("getIPAdressUrl = " + isOk);
					console.log("getIPAdressUrl = " + JSON.stringify(data));
					//失败
					if (!isOk) {
						//this.register_sub("未知");
						if (callBack) {
							callBack(address);
						}
						return;
					}
					data = JSON.parse(data || {});
					if (data.code == 0) {
						// cc.vv.GLUtils.showTips("ip地址为:"+Ip+"  玩家地址为:"+data)
						cc.log("ipAdress :", data);
						let region = data.data.region;
						let city = data.data.city;
						let country = data.data.country;
						if (city == "XX") {
							city = "";
						}
						if (region == "XX") {
							if (country == "XX") {
								country = "未知";
							}
							region = country;
						}
						if (region == city) {
							city = "";
						}
						address = region + city;
					}
					if (callBack) {
						callBack(address);
					}
				}, "json");
		*/
		/*
		//太平洋接口
		url = url + "ip=" + ip + "&json=true";
		cc.vv.GLHttpUtils.httpGets(url, false, 1, (isOk, data) => {
			console.log("getIPAdressUrl = " + isOk, data);
			// console.log("getIPAdressUrl = " + JSON.stringify(data));
			//失败
			if (!isOk) {
				//this.register_sub("未知");
				if (callBack) {
					callBack(address);
				}
				return;
			}

			data = JSON.parse(data || {});
			if (!data.err) {

				// console.log("ipAdress :", data);
				let str: string = data.addr || ""
				// console.log(str)
				address = str.split(" ")[0]
			}

			if (callBack) {
				callBack(address);
			}
		}, "json");

		*/

		//百度接口
		url = url + ip + "&co=&resource_id=6006&t=1593656437309&ie=utf8&oe=utf8&cb=op_aladdin_callback&format=json&tn=baidu&cb=jQuery110207405342301677846_1593656424310&_=1593656424313"
		cc.vv.GLHttpUtils.httpGets(url, false, 1, (isOk, data) => {
			console.log("getIPAdressUrl = " + isOk, data);
			//失败
			if (!isOk) {
				//this.register_sub("未知");
				if (callBack) {
					callBack(address);
				}
				return;
			}

			data = data + ""
			let t1 = data.split("[")[1] || ""
			let t2 = t1.split("]")[0] || "{}"
			data = JSON.parse(t2)
			console.log(data)
			if (data.location) {
				let str: string = data.location || " "
				console.log(str)
				address = str.split(" ")[0]
				address = address.replace(/省/g, "")
				address = address.replace(/市/g, "")
			}

			if (callBack) {
				console.log("address = ", address);
				callBack(address);
			}
		}, "json");
	}

	// 字符只能包含数字和英文
	checkEnglishAndNumber(str) {
		var _str = str.replace(/[^\a-\z\A-\Z0-9]/g, '')
		return _str == str
	}

	// 字符只能包含中文数字和英文
	checkChineseAndEnglishAndNumber(str) {
		var _str = str.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g, '')
		return _str == str
	}

	// 字符只能包含数字和英文和许可字符
	checkEnglishAndNumberAndPermitChar(str) {
		var _str = str.replace(/[^\a-\z\A-\Z0-9\@\.]/g, '')
		return _str == str
	}


	// 字符只能包含中文数字和英文和许可字符
	checkChineseEnglishAndNumberAndPermitChar(str) {
		var _str = str.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g, '')
		return _str == str
	}

	// 字符只能包含中文数字
	checkChineseAndNumber(str) {
		var _str = str.replace(/[^0-9\u4E00-\u9FA5]/g, '')
		return _str
	}
	// 字符只能包含中文英文
	checkChineseEnglishAndPermitChar(str) {
		var _str = str.replace(/[^\a-\z\A-\Z\u4E00-\u9FA5\@\.]/g, '')
		return _str == str
	}

	//手机号码验证
	checkPhone(phone) {
		if (!(/^1[3456789]\d{9}$/.test(phone))) {
			return false;
		}
		return true;
	}

	//获取lab的设计长度
	is32Bit(c) {
		return c.codePointAt(0) > 0xFFFF;
	}
	getViewLength(str) {
		let length = 0;
		for (let c of str) {//注意使用for of可以正确的遍历字符串的长度，而其他方法会将" "当成两个长度遍历
			if (c.codePointAt(0) > 0x00FF) {
				length = length + 2
			} else {
				length++
			}
		}	//不管是两个字节的字符如
		return length
	}






	/** 获取两点距离 p1->p2
		 * 
		 * @param p1 
		 * @param p2 
		 */
	getDistance(p1, p2) {
		return this.vvToV(cc.v2(p2.x - p1.x, p2.y - p1.y))
	}

	/** 获取两点角度 p1->p2
	 * 
	 * @param p1 
	 * @param p2 
	 */
	getAngleByPos(p1, p2) {
		return this.vvToAngle(cc.v2(p2.x - p1.x, p2.y - p1.y))
	}

	/** 获取向心速度
	 * 
	 * @param v 
	 * @param p1 
	 * @param p2 
	 */
	getCentripetalVelocity(v, p1, p2 = cc.v2(0, 0)) {
		// let R = this.getDistance(p1, p2)
		let cv = v// v * v / R
		let angle = this.getAngleByPos(p1, p2)
		return this.vToVV(cv, angle)
	}

	/** 合并两个速度  (保持vv1引用关系)
	 * 
	 * @param vv1 
	 * @param vv2 
	 */
	mergeVelocity(vv1, vv2) {

		vv1.x = this.keepDecimal(vv1.x + vv2.x)
		vv1.y = this.keepDecimal(vv1.y + vv2.y)

		return vv1;
	}

	/** 取速度值
	 * 
	 * @param vv 速度向量 
	 */
	vvToV(vv) {
		return this.keepDecimal(Math.sqrt(Math.pow(vv.x, 2) + Math.pow(vv.y, 2)))
	}

	/** 取速度向量
	 * 
	 * @param v 速度值
	 * @param angle 速度角度
	 */
	vToVV(v, angle, radian = null) {
		if (!radian && radian != 0) {
			radian = this.angleToRadian(angle)
		}

		let x = this.keepDecimal(Math.cos(radian)) * v
		let y = this.keepDecimal(Math.sin(radian)) * v

		return cc.v2(x, y)
	}


	/** 取速度角度
	 * 
	 * @param vv 
	 */
	vvToAngle(vv) {
		return this.radianToAngle(Math.atan2(vv.y, vv.x));

	}

	/** 角度转弧度
	 * 
	 * @param angle 与X轴正半轴 逆时针的 角度
	 */
	angleToRadian(angle) {
		return this.keepDecimal(Math.PI / 180 * angle);
	}

	/** 弧度转角度
	 * 
	 * @param radian 
	 */
	radianToAngle(radian) {
		return this.keepDecimal(180 / Math.PI * radian);
	}
	/** 保留小数点后 n 位
	 * 
	 * @param num 
	 * @param n n位 默认2
	 */
	keepDecimal(num, n = 2) {
		let t = Math.pow(10, n);
		return Math.round(num * t) / t;
	}
	binarraytoString(binary) {
		var view = new DataView(binary)
		var s = []
		for (var i = 0; i < view.byteLength; i++) {
			var char = view.getUint8(i, true)

			if (char != 0 && char != 52428) {
				s.push(char)
			}
		}
		var result = "";
		for (let i = 0; i < s.length; ++i) {
			result += String.fromCharCode(s[i])
		}
		return result;
	}

	changeCanvasToHorizontal() {
		// 从大厅进入游戏  横竖屏切换 切换到横屏
		// 切换到横屏
		cc.log("切换到横屏")
		// cc.vv.GLConfig.currentOrientation = 1;
		// if (cc.sys.isNative) {
		// 	if (cc.sys.os == cc.sys.OS_ANDROID) {
		// 		cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE)
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).designResolution = cc.size(1334, 750)
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitHeight = true
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitWidth = false
		// 		jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "changeOrientationH", "(I)V", 1);
		// 	}
		// 	if (cc.sys.os == cc.sys.OS_IOS) {
		// 		cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE)
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).designResolution = cc.size(1334, 750)
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitHeight = true
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitWidth = false
		// 		jsb.reflection.callStaticMethod("AppController", "changeOrientationH:", 1);
		// 	}
		// } else {
		// 	cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE)
		// 	cc.director.getScene().children[0].getComponent(cc.Canvas).designResolution = cc.size(1334, 750)
		// 	cc.director.getScene().children[0].getComponent(cc.Canvas).fitHeight = true
		// 	cc.director.getScene().children[0].getComponent(cc.Canvas).fitWidth = false
		// }
	}
	changeCanvasToVertical() {
		// 切换到竖屏
		// cc.log("切换到竖屏")
		// cc.vv.GLConfig.currentOrientation = 0;
		// if (cc.sys.isNative) {
		// 	if (cc.sys.os == cc.sys.OS_ANDROID) {
		// 		jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "changeOrientationH", "(I)V", 0);
		// 		cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT)
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).designResolution = cc.size(750, 1334);
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitHeight = false;
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitWidth = true;
		// 	}
		// 	if (cc.sys.os == cc.sys.OS_IOS) {
		// 		cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT)
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).designResolution = cc.size(750, 1334);
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitHeight = false;
		// 		cc.director.getScene().children[0].getComponent(cc.Canvas).fitWidth = true;
		// 		jsb.reflection.callStaticMethod("AppController", "changeOrientationH:", 0);
		// 	}
		// } else {
		// 	cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT)
		// 	cc.director.getScene().children[0].getComponent(cc.Canvas).designResolution = cc.size(750, 1334);
		// 	cc.director.getScene().children[0].getComponent(cc.Canvas).fitHeight = false;
		// 	cc.director.getScene().children[0].getComponent(cc.Canvas).fitWidth = true;
		// }
	}

	/**
	 * 获取字符串字符实际长度(中英)
	 * @param val 
	 */
	public getStringByLen(val: string): number {
		let result: number = 0
		if (val && val.length > 0) {
			for (let i = 0; i < val.length; i++) {
				let tempC = val.charAt(i)
				if (tempC.match(/[^\x00-\xff]/ig) != null)
					result += 2
				else
					result++
			}
		}
		return result
	}

	base64_decode(str) {
		var c1, c2, c3, c4;
		var base64DecodeChars = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
		-1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57,
			58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6,
			7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
			25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
			37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1,
		-1, -1];
		var i = 0, len = str.length, string = "";
		while (i < len) {
			do {
				c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
			} while (
				i < len && c1 == -1
			);
			if (c1 == -1) break;
			do {
				c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
			} while (
				i < len && c2 == -1
			);
			if (c2 == -1) break;
			string += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
			do {
				c3 = str.charCodeAt(i++) & 0xff;
				if (c3 == 61)
					return string;
				c3 = base64DecodeChars[c3];
			} while (
				i < len && c3 == -1
			);
			if (c3 == -1) break;
			string += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
			do {
				c4 = str.charCodeAt(i++) & 0xff;
				if (c4 == 61) return string;
				c4 = base64DecodeChars[c4];
			} while (
				i < len && c4 == -1
			);
			if (c4 == -1) break;
			string += String.fromCharCode(((c3 & 0x03) << 6) | c4);
		}
		return string;
	}

	loadBase64Image(data, name, callback, isClear) {
		if (!cc.sys.isNative) {
			var base64 = "data:image/jpeg;base64," + data;
			var img = new Image();
			img.src = base64;
			img.onload = function () {
				var texture = new cc.Texture2D();
				texture.initWithElement(img);
				texture.handleLoadedTexture();
				var newframe = new cc.SpriteFrame(texture);
				if (callback) callback(newframe);
			}
			return;
		}
		if (typeof isClear == "undefined") {
			isClear = true;
		}

		var dirpath = cc.vv.GLConfig.storageImgPath;// jsb.fileUtils.getWritablePath() + 'img/';
		var filename = name;
		var filepath = dirpath + filename;
		console.log("filepath:", filepath);

		function loadEnd() {
			cc.loader.load(filepath, function (err, tex) {
				if (err) {
					cc.error(err);
				} else {
					var spriteFrame = new cc.SpriteFrame();
					spriteFrame.setTexture(tex);
					if (spriteFrame) {
						callback(spriteFrame);
					}
				}
			});
		}

		var saveFile = function (dataa) {
			if (typeof dataa !== 'undefined') {
				if (!jsb.fileUtils.isDirectoryExist(dirpath)) {
					jsb.fileUtils.createDirectory(dirpath);
				}
				var img = cc.vv.GLUtils.base64_decode(dataa);
				var dataLen = img.length;
				var arrData = new Uint8Array(img.length);
				for (var i = 0; i < dataLen; i++) {
					arrData[i] = img.charCodeAt(i);
				}
				console.log("arrData  is ", arrData.length)
				if (jsb.fileUtils.writeDataToFile(arrData, filepath)) {
					cc.log('缓存本地成功:' + filename);
					loadEnd();
				} else {
					cc.log('缓存本地失败:' + filename);
				}
			} else {
				cc.log('缓存本地失败:' + filename);
			}
		};

		if (jsb.fileUtils.isFileExist(filepath) && isClear == false) {//是否读取缓存
			cc.log('读取本地缓存：' + filepath);
			loadEnd();
			return;
		}
		jsb.fileUtils.removeFile(filepath);
		saveFile(data);
	}


	//原生平台本地图片缓存 只能缓存png
	loadImageNativeWithUrl(url, callback, filename, dirpath, suffix) {
		suffix = suffix || 'png';
		var filepath = dirpath + filename + "." + suffix;
		function loadEnd() {
			cc.loader.load(filepath, function (err, tex) {
				if (err) {
					cc.error(err);
					callback(err, false);
				} else {
					var spriteFrame = new cc.SpriteFrame(tex);
					if (spriteFrame) {
						callback(spriteFrame, true);
					}
				}
			});
		}

		if (jsb.fileUtils.isFileExist(filepath)) {
			cc.log('Remote is find' + filepath);
			loadEnd();
			return;
		}

		var saveFile = function (data) {
			if (typeof data !== 'undefined') {
				if (!jsb.fileUtils.isDirectoryExist(dirpath)) {
					jsb.fileUtils.createDirectory(dirpath);
				}
				console.log("data,", JSON.stringify(data));
				console.log("filepath,", filepath);

				if (jsb.fileUtils.writeDataToFile(new Uint8Array(data), filepath)) {
					loadEnd();
				} else {
					cc.log('Remote write file failed.');
				}
			} else {
				cc.log('Remote download file failed.');
			}
		};

		var xhr = new XMLHttpRequest();

		xhr.onreadystatechange = function () {
			if (xhr.readyState === 4) {
				if (xhr.status === 200) {
					saveFile(xhr.response);
				} else {
					saveFile(null);
				}
			}
		}.bind(this);
		xhr.responseType = 'arraybuffer';
		xhr.open("GET", url, true);
		xhr.send();
	}

	testChat(session, type, str) {
		let msg = {
			session: session,
			chat_type: type,
			data_type: 1,
			data: str,
		}
		cc.vv.GLUtils.sendRequest("SendMsg", msg, (error, data) => {
			console.log("data  is  ", data)
			console.log("error  is  ", error)
			cc.vv.eventCustom.emit("editboxchange", "")
			if (!data.errordes) {
			} else {
				//保存没有发送成功的消息
				cc.vv.GLUtils.showTips(data.errordes);
				cc.vv.chatMgr.insertOneMessage(null, msg, null, false, true)
			}
		});
	}


	/** 测试时打印错误信息,以及调用堆栈
	 * 
	 * @param ...arg 
	 */
	testErrorLog(...arg) {
		cc.error("错误描述:", Array.prototype.slice.call(arguments), "\n", new Error("调用堆栈:"))
	}
	/** 向左合并
	 * 
	 * 将ab 都有的数据从b中覆盖到a中
	 * 
	 * 用于已有数据向默认数据覆盖
	 */
	merge_left(a, b) {
		if (!a || !b) {
			return a
		}
		for (const key in b) {
			if (a[key]) {
				a[key] = JSON.parse(JSON.stringify(b[key]))
			}
		}
		return a;
	}
	/** 标签宽度限制
	  * 
	  * @param lbl 
	  * @param maxWidth 
	  * 
	  * 主要用于fnt字体,缩放时显示不居中的情况
	  */
	lableWidthLimit(lbl: cc.Label, maxWidth: number) {
		if (maxWidth <= 0 || !lbl || !lbl["_forceUpdateRenderData"]) {
			cc.error("参数错误")
			return;
		}
		lbl._forceUpdateRenderData();
		let width = lbl.node.width
		if (width <= 0) {
			return
		}
		let scale = (maxWidth / width)
		scale > 1 ? scale = 1 : scale
		lbl.node.scale = scale
	}
	numberToChinese(number) {
		let unitConfig = [
			"",
			"s",
			"b",
			"q",

		]
		let specialUnitConfig = {
			"4": "w",
			"5": "y",
			"6": "z",
			"7": "j",

			"w": "4",
			"y": "5",
			"z": "6",
			"j": "7",
		}
		let numberConfig = {
			"1": "一",
			"2": "二",
			"3": "三",
			"4": "四",
			"5": "五",
			"6": "六",
			"7": "七",
			"8": "八",
			"9": "九",
			"0": "零",
			"s": "十",
			"b": "百",
			"q": "千",
			"w": "万",
			"y": "亿",
			"z": "兆",
			"j": "京",
		}

		let sUnit = 0;
		let mUnit = 4;
		let stand = 4; //4进1   个十百千 进一
		let temp = ""
		let string = number + ""
		let len = string.length;
		for (let i = len - 1; i >= 0; i--) {
			let c = string[i];

			let t = "", tu = ""
			if (sUnit >= stand) {
				tu = specialUnitConfig[mUnit]
				mUnit++
				sUnit = 1;
			} else {
				t = unitConfig[sUnit]
				sUnit++
			}
			if (c == "0") {
				if (temp != "") {
					if (temp[0] <= "0" || temp[0] >= "9") {
						if (tu && specialUnitConfig[temp[0]]) {
							temp = temp.slice(1, temp.length)
						}
						if (temp[0] != "0") {
							temp = c + temp;
						}
					} else if (!tu) {
						temp = c + temp;
					}

				}
				temp = tu + temp;
			} else {
				temp = c + tu + t + temp;
			}

		}
		let res = ""
		for (let i = 0, len = temp.length; i < len; i++) {
			let c = temp[i];
			res += numberConfig[c]
		}
		return res;
	}
	/**
	 * @function 求两个数组的交集
	 * @description 数组为简单数组
	 * @returns {array} 正常的数组
	 * */
	intersection(aArray, bArray) {
		let bArraySet = new Set(bArray);
		let resultArray = aArray.filter(item => bArraySet.has(item));
		return Array.from(resultArray);
	}

	/**
	 * @function 求两个数组的并集
	 * @description 数组为简单数组
	 * @returns {array} 正常的数组
	 * */
	union(aArray, bArray) {
		let resultArray = new Set([...aArray, ...bArray]);
		return Array.from(resultArray);
	}

	/**
	 * @function 求两个数组的差集;数组aArray相对于bArray所没有的
	 * @description 数组为简单数组
	 * @returns {array} 正常的数组
	 * */
	difference(aArray, bArray) {
		let bArraySet = new Set(bArray);
		let resultArray = aArray.filter(item => !bArraySet.has(item));
		return Array.from(resultArray);
	}

	getPhoneType(){
	    return cc.sys.os == cc.sys.OS_ANDROID ? "安卓":"苹果";
    }

}
export let glUtils: Utils = new Utils(); //
